<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<body th:fragment="tooth_function">
    <div class="wonderful-top">

        <div class="top-list top-list-one">
            <div id="fun_xzx" th:onclick="mytext('zx')">
                <a href="javascript:;" target="_self">
                    <img src="/icon/icon_Questions.png" alt="有贝口腔网">
                    <span>写文章</span>
                </a>
            </div>
            <div th:onclick="mytext('wd')">
                <a href="javascript:;" target="_self">
                    <img src="/icon/icon_Articles.png" alt="有贝口腔网">
                    <span>提问题</span>
                </a>
            </div>
        </div>
        <div class="top-list top-list-two">
            <div>
                <a href="javascript:;" target="_self" onclick="showPlanFun()">
                    <img src="/icon/Dentist.png" alt="有贝口腔网">
                    <span>网上看牙</span>
                </a>
            </div>
            <div>
                <a href="javascript:;" target="_self" onclick="showPlanFun()">
                    <img src="/icon/Factory.png" alt="有贝口腔网">
                    <span>厂家入驻</span>
                </a>
            </div>
            <div>
                <a href="javascript:;" target="_self" onclick="showPlanFun()">
                    <img src="/icon/Hospital.png" alt="有贝口腔网">
                    <span>诊所入驻</span>
                </a>
            </div>
        </div>
    </div>

    <div th:replace="~{common/hasbei_text::hasbei_text}"></div>


<script type="text/javascript">

    //提示功能在开发中
    function showPlanFun(){
        layer.msg("功能即将开放，敬请期待，欢迎关注有贝口腔网");
    }

    function getCookie(cookieName) {
        var strCookie = document.cookie;
        var arrCookie = strCookie.split("; ");
        for(var i = 0; i < arrCookie.length; i++){
            var arr = arrCookie[i].split("=");
            if(cookieName == arr[0]){
                return arr[1];
            }
        }
        return "";
    }


    function mytext(value) {
            console.log("写文章 ------》")
            $.get("/userProve",function (item) {
                console.log(item);
                if(item.code==201){
                    $("#form-title").text("");
                    if(value=="zx"){
                        $("#form-title").attr("placeholder","请输入文章标题（5-100个汉字）")
                        editor.txt.html('<p id="myplaceholder" style="color: #999">请输入相关口腔文章、资讯内容</p>')

                        //$("#myplaceholder").text("请输入相关口腔文章、资讯内容")
                        layer.open({
                            title: "發表文章"
                            , content: $('#mytext')
                            , type: 1
                            , area: ["auto", "auto"]
                            , anim: 5
                            , btn: ['提交', '取消']
                            ,yes: function(index, layero){
                                var title=$("#form-title").val();
                                var content=editor.txt.html();

                                var userId = getCookie("userId");
                                if(userId==null){
                                    layer.msg("登录已过期，请重新登录！！！");
                                    return false;
                                }

                                var essayimg = $("#editor img")[0];
                                if(essayimg!=null){
                                    essayimg=essayimg.currentSrc;
                                }
                                console.log("图片   "+essayimg+" 用户ID"+userId)

                                var classType = $("#classType").find("option:selected").attr("classid");
                                console.log(classType);
                                if(classType==null){
                                    layer.msg("请选择文章类型！！！");
                                    return false;
                                }

                                if(title.length <= 5 && title.length < 100){
                                    layer.msg("文章标题（5-100个汉字）");
                                    return false;
                                }
                                if(editor.txt.text().length < 50){
                                    layer.msg("文章内容至少输入50字数");
                                    return false;
                                }

                                var data={
                                    title,
                                    content,
                                    classType,
                                    essayimg,
                                    userId
                                };
                                console.log(data);
                                $.post("/zxAdd",data,function (item) {
                                    if(item.code == 201){
                                        //按钮【按钮一】的回调
                                        layer.msg("文章发表成功，待审核",function(){
                                            $("#form-title").val("");
                                            layer.closeAll(); //疯狂模式，关闭所有层
                                        })
                                    }else{
                                        layer.msg(item.message);
                                    }

                                })

                            }
                            ,btn2: function(index, layero){
                                //按钮【按钮二】的回调
                                //return false 开启该代码可禁止点击该按钮关闭
                                $("#form-title").val("");
                                editor.txt.html('<p><br></p>');
                            }

                        });
                    }
                    if(value=="wd"){
                        $("#form-title").attr("placeholder","请输入口腔问题（5-100个汉字）以?号结尾")
                        editor.txt.html('<p id="myplaceholder" style="color: #999">【非必填】，描述该口腔问题背景，如什么情况下产生这个问题</p>')

                        layer.open({
                            title: "發表口腔问题"
                            , content: $('#mytext')
                            , type: 1
                            , area: ["auto", "auto"]
                            , anim: 5
                            , btn: ['提交', '取消']
                            ,yes: function(index, layero){
                                var title=$("#form-title").val();
                                var content=editor.txt.html();

                                var userId = getCookie("userId");
                                if(userId==null){
                                    layer.msg("登录已过期，请重新登录！！！");
                                    return false;
                                }

                                var essayimg = $("#editor img")[0];
                                if(essayimg!=null){
                                    essayimg=essayimg.currentSrc;
                                }
                                console.log("图片   "+essayimg+" 用户ID"+userId)

                                var classType = $("#classType").find("option:selected").attr("classid");
                                console.log(classType);
                                if(classType==null){
                                    layer.msg("请选择文章类型！！！");
                                    return false;
                                }

                                if(title.length <= 5 && title.length < 100){
                                    layer.msg("文章标题（5-100个汉字）");
                                    return false;
                                }
                                if(editor.txt.text().length < 50){
                                    layer.msg("文章内容至少输入50字数");
                                    return false;
                                }

                                var data={
                                    title,
                                    content,
                                    classType,
                                    essayimg,
                                    userId
                                };
                                console.log(data);
                                $.post("/qaAdd",data,function (item) {
                                    if(item.code == 201){
                                        //按钮【按钮一】的回调
                                        layer.msg("问题发表成功，待审核",function(){
                                            $("#form-title").val("");
                                            layer.closeAll(); //疯狂模式，关闭所有层
                                        })
                                    }else{
                                        layer.msg(item.message);
                                    }

                                })
                            }
                            ,btn2: function(index, layero){
                                //按钮【按钮二】的回调
                                //return false 开启该代码可禁止点击该按钮关闭
                                $("#form-title").val("");
                                editor.txt.html('<p><br></p>');
                            }
                        });
                    }
                }else{
                    layer.msg("请先登录！！！")
                    return false;
                }
            })
        }
</script>

</body>
</html>